<!-- 立项申请 - 经营负责人节点 -->
<template>
  <a-spin :spinning="confirmLoading" style="background: #fff">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectNo">
              <a-input :disabled="isDisableProjectNo" v-model="model.projectNo" placeholder="请输入单据编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                placeholder="请选择申请时间"
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <!--              <select-user-by-dep-->
              <!--                :disabled=formDisabled-->
              <!--                v-model="model.proposer" disabled/>-->
              <select-user-by-dep :multi="false" v-model="model.proposer" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled/>
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-col :span="12">
            <a-form-model-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPrepareEstablish">
              <!-- <j-dict-select-tag :disabled=formDisabled @input="isPrepareEstablishChange" type="radio"
                                v-model="model.isPrepareEstablish" dictCode="YES_OR_NO"
                                placeholder="请输入是否预立项"></j-dict-select-tag> -->
              <!-- <j-dict-select-tag :disabled=formDisabled type="list"  :key="5" @input="handleInput" v-model="model.isPrepareEstablish" dictCode="omc_project_type" placeholder="请选择数据来源" /> -->
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                @input="isPrepareEstablishChange"
                v-model="model.isPrepareEstablish"
                dictCode="omc_project_type"
                placeholder="请选择数据来源" />
            </a-form-model-item>
          </a-col>

          <a-col :span="12" v-if="model.isPrepareEstablish == '0'" >
            <!-- <a-col :span="12" v-if="isShowPrepareProject" > -->
            <a-form-model-item label="预立项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="finalProjectId">
              <select-project-input
                :proDisabled="proDisabled"
                :projectStatus="'1'"
                :disabled="formDisabled"
                v-model="model.finalProjectId"
                :changeStatus="'unchanged'"
                :tenderStatus="'0'"
                @back="prepareProjectChange"/>
              <!--              <a-input v-if="!isShowPrepareProject"  v-model="model.projectName" placeholder="请输入项目名称"></a-input>-->
            </a-form-model-item>
          </a-col>

          <!-- <a-col :span="12" v-if="isShowPrepareProject" > -->
          <a-col :span="12" v-if="model.isPrepareEstablish == '1'" >
            <a-form-model-item label="投标档案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFinalCode">
              <!-- <SelectOmcTenderFileInput
                :proDisabled="proDisabled"
                :projectStatus="'1'"
                :disabled="formDisabled"
                v-model="model.finalProjectId"
                :changeStatus = "'unchanged'"
                @back="prepareProjectChange"/> -->
              <!-- <j-popup
                    :disabled=formDisabled
                    v-model="model.tenderFinalCode"
                    field="tenderFinalId"
                    placeholder="请选择投标编号"
                    dest-fields="tenderFinalId,prepareProjectId,id"
                    org-fields ="final_no,prepare_project_id,id"
                    code="erp_omc_tender_final_model"
                    @input="popupCallback"
                  /> -->
              <select-omc-project-tender-input :query-type="'prepare'" :disabled="formDisabled" :isBid="1" v-model="model.tenderFinalCode" @back="tenderFinalChange"/>
            </a-form-model-item>
            <!--              <a-input v-if="!isShowPrepareProject"  v-model="model.projectName" placeholder="请输入项目名称"></a-input>-->

          </a-col>

          <!-- <a-col :span="12" v-if="!isShowPrepareProject" > -->
          <!-- <a-col :span="12" v-if="isShowPrepareProject" > -->
          <a-col :span="12" >
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input v-if="!formDisabled" @change="changeTitle" :disabled="formDisabled" v-model="model.projectName" placeholder="请输入项目名称"></a-input>
              <p v-else style="display: flex; align-items: center; justify-content: center; margin: 0;">
                <a-input :disabled="formDisabled" v-model="model.projectName" placeholder="请输入项目名称"></a-input>
                <a-button v-if="formData && formData.tableValue && formData.tableValue == '待办'" @click.stop="onCheckProjectName(model.projectName)" type="danger" ghost>校重检验</a-button>
              </p>
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="12">-->
          <!--&lt;!&ndash;            <a-form-model-item label="是否招投标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isBidding">&ndash;&gt;-->
          <!--            <a-form-model-item label="是否分配" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isBidding">-->
          <!--              <j-dict-select-tag :disabled=formDisabled type="radio" value="0" v-model="model.isBidding"-->
          <!--                                 dictCode="YES_OR_NO" placeholder="请输入是否分配"></j-dict-select-tag>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="12">-->
          <!--            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">-->
          <!--              <a-input :disabled=formDisabled v-model="model.projectName" placeholder="请输入项目名称"></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="12">-->
          <!--            <a-form-model-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectType">-->
          <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.projectType" dictCode="xmlx_type"-->
          <!--                                 placeholder="请选择项目类型"/>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamName">
              <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.teamName" dictCode="teams" placeholder="请选择经营团队" />-->
              <select-team-input
                :disabled="formDisabled"
                v-model="model.teamName"
                :tdlx="1"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <!--              <select-user-by-dep-->
              <!--                  :disabled=formDisabled-->
              <!--                  v-model="model.undertaker"/>-->
              <select-user-by-dep :disabled="formDisabled" :multi="false" v-model="model.undertaker" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="立项日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectEstablishDate">
              <j-date
                :disabled="formDisabled"
                placeholder="请选择立项日期"
                v-model="model.projectEstablishDate"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signUnit">
              <!--              <j-select-company :disabled=formDisabled placeholder="请选择签订单位" v-model="model.signUnit"/>-->
              <select-Company-input :disabled="formDisabled" placeholder="请选择签订单位" v-model="model.signUnit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.year"
                dictCode="yjgsnd"
                placeholder="请选择归属年度"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="是否环评项目"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="isEnvironmentalAssessmentProject">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="radio"
                v-model="model.isEnvironmentalAssessmentProject"
                dictCode="YES_OR_NO"
                placeholder="请选择是否环评项目"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
              <!--              <a-input :disabled=formDisabled v-model="model.ownerUnit" placeholder="请输入业主单位"  ></a-input>-->
              <select-customer-input
                :disabled="formDisabled"
                v-model="model.ownerUnit"
                commercialType="1"
                @change="ownerUnitChange"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contacts">
              <j-dict-select-tag
                :disabled="formDisabled || !model.ownerUnit"
                type="list"
                v-model="model.contacts"
                :dictCode="this.customer_contacts"
                placeholder="请选择联系人"
                @input="contactsChange"
                :triggerChange="false"/>
              <!-- <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-else
                v-model="model.contacts"
                :dictCode="this.customer_contacts"
                placeholder="请选择联系人"
                @input="contactsChange"
                :triggerChange="false"/> -->
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactTel">
              <a-input :disabled="formDisabled" v-model="model.contactTel" placeholder="请输入联系方式"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业主角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerRole">
              <j-dict-select-tag
                :disabled="formDisabled"
                v-model="model.ownerRole"
                dictCode="owner_role"
                placeholder="请选择业主角色"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="企业类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseType">
              <j-dict-select-tag disabled type="list" v-model="model.enterpriseType" dictCode="enterprise_type" placeholder="请选择企业类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="项目所在地址"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="height:65px"
              prop="projectAddress" >
              <a-form-model-item :style="{display:'inline-block',width:'48%'}" prop="areaCode">
                <!--                <j-area-linkage :disabled=formDisabled type="cascader" v-model="model.areaCode" placeholder="请输入省市区"/>-->
                <AddressChoice :disabled="formDisabled" v-model="model.areaCode" placeholder="请选择省市区"></AddressChoice>
              </a-form-model-item>
              <a-form-model-item
                :style="{'margin-top':'0px','margin-left':'5px',display:'inline-block',width:'50%'}"
                prop="projectAddress">
                <a-input :disabled="formDisabled" v-model="model.projectAddress" placeholder="请输入项目详细地址"></a-input>
              </a-form-model-item>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectSource">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.projectSource"
                dictCode="xmly_type"
                placeholder="请选择项目来源"/>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="台账管理员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountAdmin">
              <select-user-by-dep
                  :disabled=formDisabled
                  v-model="model.accountAdmin"/>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item
              label="预计合同额（元）"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="estimatedContractAmount">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.estimatedContractAmount"
                placeholder="请输入预计合同额"
                style="width: 100%"
                @blur="convertMoney"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="预计合同额大写"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="estimatedContractcapitalChineseAmount">
              <a-input
                v-model="model.estimatedContractcapitalChineseAmount"
                placeholder="请输入预计合同额大写"
                disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="经营绩效(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="businessPerformance">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.businessPerformance"
                placeholder="请输入经营绩效"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item
              label="分配方式"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="distributionMethod">

                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.distributionMethod"
                  dictCode="distribution_method"
                  placeholder="请选择分配方式" @change="getForMoney()"/>

            </a-form-model-item>
          </a-col> -->

          <!--          <a-col :span="12">-->
          <!--            <a-form-model-item label="项目内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outline">-->
          <!--              <a-textarea :disabled=formDisabled v-model="model.outline" rows="4" placeholder="请输入项目内容概要"/>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="立项事由及说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="establishReason">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.establishReason" rows="4" placeholder="请输入立项事由及说明"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
          <a-form-model-item
              label="分配方式"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="distributionMethod">

                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.distributionMethod"
                  dictCode="distribution_method"
                  placeholder="请选择分配方式" @change="getForMoney()"/>

            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="主生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainProductionTeam">
              <select-team-input
                :disabled="mainProduction"
                v-model="model.mainProductionTeam"
                :teamType="0"
                :tdlx="2"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="相关附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachment">
              <j-upload :disabled="formDisabled" if="!formDisabled" v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
          <!-- <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col> -->
        </a-row>
        <a-col :span="24" style="margin-bottom: 24px">
          <div style="margin-bottom: 6px;margin-top: 6px">
            <a-button @click="addOrEdit('')" type="primary">新增</a-button>
          </div>
          <a-table
            ref="table"
            :scroll="{x:'100%'}"
            :components="draggableComponent"
            size="middle"
            rowKey="id"
            bordered
            :loading="loading"
            :columns="columns"
            :pagination="false"
            :data-source="dataSource">
            <span slot="action" slot-scope="text, record">
              <template>
                <a-button
                  class="ruleButton"
                  :ghost="true"
                  type="primary"
                  icon="edit"
                  @click="addOrEdit(record)"/>
                <a-divider type="vertical"/>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="delete"
                  />
                </a-popconfirm>
              </template>
            </span>
            <!-- <span slot="modelAndViewRender" slot-scope="text, record"> -->
            <!-- <j-ellipsis :value="text" :length="10"/>
            </span> -->
<!--            <template slot="titleSlot" slot-scope="text">-->
<!--              <span v-if="text">-->
<!--                {{ text }}%-->
<!--              </span>-->
<!--              <span v-if="!text">-->
<!--                - -->
<!--              </span>-->
<!--            </template>-->
          </a-table>
        </a-col>
      </a-form-model>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <erp-my-omc-project-task-modal ref="categoryList" @ok="modalFormOk" :distributionMethod="model.distributionMethod"/>
    <!-- <erp-my-omc-project-task-list :allow-change="allowChange"
                                            ref="categoryList"></erp-my-omc-project-task-list> -->
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>
    <ErpOmcPrepareProjectNameCheckModal ref="ErpOmcPrepareProject"></ErpOmcPrepareProjectNameCheckModal>
    <ErpOmcProjectApplyFormPrint class="print_style" v-if="formBpm" id="projectapplyContent" :formData="model" :formDataHistory="formData"/>
  </a-spin>
</template>

<script>
import SelectProjectInput from '@/views/scy/components/SelectProjectInput';
import { getAction, httpAction } from '@/api/manage'
import SelectTeamInput from '@views/scy/components/SelectTeamInput';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput';
import { convertCurrency } from '@/utils/MoneyConvert';
import ErpMyOmcProjectTaskModal from '@views/erp/omc/project/modules/reference/ErpMyOmcProjectTaskModal';
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import { mapGetters } from 'vuex';
import moment from 'moment';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import SelectOmcProjectTenderInput from '@/views/scy/components/SelectOmcProjectTenderInput';
import CommonFlowList from '@/views/components/CommonFlowList.vue';
import Print from '@/utils/print/printarea.js';
import ErpOmcProjectApplyFormPrint from './ErpOmcProjectApplyFormPrint' // 立项打印
import ErpOmcPrepareProjectNameCheckModal from '@/views/erp/omc/prepareproject/modules/ErpOmcPrepareProjectNameCheckModal' // 项目名称校验
import { DragResizable } from '@/mixins/DragResizable'
export default {
  name: 'ErpOmcProjectApplyForm',
  components: {
    ErpMyOmcProjectTaskModal,
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    SelectProjectInput,
    AddressChoice,
    SelectCompanyInput,
    // SelectOmcTenderFileInput,
    SelectOmcProjectTenderInput,
    CommonFlowList,
    ErpOmcProjectApplyFormPrint,
    ErpOmcPrepareProjectNameCheckModal
  },
  mixins: [DragResizable],
  props: {
    allowChange: {
      type: Boolean,
      default: false,
      required: false
    },
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      isPrint: false,
      isShowPrepareProject: false,
      isDisableProjectNo: false,
      model: {
        isEnvironmentalAssessmentProject: '0',
        // isPrepareEstablish: '0',
        isBidding: '0'
      },
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      validatorRules: {
        // bpmBizTitle: [
        //   { required: true, message: '请输入流程名称!' },
        // ],
        // task#2118 是否环评改为必填项，默认为否
        isEnvironmentalAssessmentProject: [
          { required: true, message: '请输入是否环评!' }
        ],
        finalProjectId: [
          { required: true, message: '请选择预立项!' }
        ],
        prepareProjectId: [
          { required: true, message: '请输入预立项!' }
        ],
        projectId: [
          { required: true, message: '请输入已立项项目!' }
        ],
        projectNo: [
          { required: true, message: '请输入已立项项目编号!' }
          // { validator: (rule, value, callback) => validateDuplicateValue('erp_omc_project', 'project_no', value, this.model.id, callback)},
        ],
        distributionMethod:[
          { required: true, message: '请选择分配方式!' }
        ],
        projectName: [
          { required: true, message: '请输入项目名称!' }
        ],
        teamName: [
          { required: true, message: '请输入经营团队!' }
        ],
        undertaker: [
          { required: true, message: '请输入项目承接人!' }
        ],
        projectEstablishDate: [
          { required: true, message: '请输入立项日期!' }
        ],
        signUnit: [
          { required: true, message: '请输入签订单位!' }
        ],
        year: [
          { required: true, message: '请输入业绩归属年度!' }
        ],
        ownerUnit: [
          { required: true, message: '请输入业主单位!' }
        ],
        contacts: [
          { required: true, message: '请输入联系人!' }
        ],
        areaCode: [
          { required: true, message: '请选择项目区域!' }
        ],
        projectAddress: [
          { required: true, message: '请输入项目所在地址!' }
        ],
        projectSource: [
          { required: true, message: '请输入项目来源!' }
        ],
        // task#2118 立项事由及说明非必填
        // establishReason: [
        //   { required: true, message: '请输入立项事由及说明!' }
        // ],
        estimatedContractAmount: [
          { required: true, message: '请输入预计合同额!' },
          // { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          { pattern: /^-?(([0-9]*(\.[0-9]{1,3})$)|([0-9]+$))/, message: '请输入正确的金额!' }
        ],
        businessPerformance: [
          { required: true, message: '请输入经营绩效!' },
          { pattern: /^-?(([0-9]*(\.[0-9]{1,3})$)|([0-9]+$))/, message: '请输入正确的金额!' }
        ],
        contactTel: [
          { required: true, message: '请输入联系方式!' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        // 2022/10/27 - 迭代11需求
        isPrepareEstablish: [
          { required: true, message: '请选择数据来源!' }
        ]
      },
      url: {
        add: '/api/erp/omc/project/erpOmcProjectApply/add',
        edit: '/api/erp/omc/project/erpOmcProjectApply/editProject',
        queryById: '/api/erp/omc/project/erpOmcProjectApply/queryById',
        queryPrepareProjectById: '/api/erp/omc/prepareproject/erpOmcPrepareProject/queryById',
        queryProjectById: '/api/erp/omc/project/erpOmcProject/queryById',
        getProjectNo: '/api/erp/omc/project/erpOmcProjectApply/getProjectNo',
        generatedFormNumber: '/api/erp/base/generatedFormNumber',
        queryTenderServiceListByTenderId: '/api/erp/omc/tender/erpOmcTenderServiceFinal/queryTenderServiceListByTenderId',
        queryTenderResultByEntity: '/api/erp/omc/tender/erpOmcTenderResultFinal/queryTenderResultByEntity'
      },
      customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
      // customer_contacts: '',
      loading: false,
      dataSource: [],

      // 迭代11
      unitDataSource: [],
      dictOptions: {},
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '业务分类编码',
          align: 'center',
          dataIndex: 'categoryCode',
          ellipsis: true,
          width: 180
        },
        {
          title: '业务分类名称',
          align: 'center',
          dataIndex: 'categoryName',
          ellipsis: true,
          width: 300
        },
        {
          title: '合同占比（%）',
          align: 'center',
          dataIndex: 'contractRate',
          ellipsis: true,
          width: 150
          // bug 6151
         // scopedSlots: { customRender: 'titleSlot' }
        },
        {
          title: '分配合同额(元)',
          align: 'center',
          dataIndex: 'contractAmount',
          ellipsis: true,
          width: 150
        },
        {
          title: '切割合同额(元)',
          align: 'center',
          dataIndex: 'cutContractAmount',
          width: 130,
          ellipsis: true
        },
        {
          title: '生产团队',
          align: 'center',
          dataIndex: 'productTeam',
          ellipsis: true,
          width: 320,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['productTeam'], text + '')
            }
          }
        },
        {
          title: '团队负责人',
          align: 'center',
          dataIndex: 'teamLeader',
          ellipsis: true,
          width: 160,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['teamLeader'], text + '')
            }
          }
        },
        {
          title: '任务说明',
          align: 'center',
          dataIndex: 'taskDescription',
          width: 250,
          ellipsis: true,
          scopedSlots: { customRender: 'modelAndViewRender' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed: 'right',
          width: 150,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ]
    }
  },
  computed: {
    proDisabled() {
      return true
    },
    formDisabled() {
      return true
    },

    mainProduction() {      
      if (this.formBpm === true) {
        if (this.formData.taskDefKey === 'task1744342861475') {
          return false
        }
      }
      if(this.formBpm === false){
        return false
      }

      return true
    },

    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    this.model.applyType = '1'
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    // 加载数据字典信息
    this.initDictConfig();
    // if (this.formDisabled) {
    //   this.columns.pop()
    // }
    this.customKey = 'columns'
    this.columnswidth = this.columns.map(val => {
      return val.width
    })
  },
  methods: {
    ...mapGetters(['userInfo']),
    // 点击项目名称按钮校验
    onCheckProjectName (value) {
      this.$refs.ErpOmcPrepareProject.getDetail()
    },
    changeTitle() {
      this.model.bpmBizTitle = this.model.projectName
    },
    // 加载数据字典信息
    initDictConfig() {
      initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'productTeam', res.result)
        }
      })
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'teamLeader', res.result)
        }
      })
    },
    handleNumberChange(e) {
      this.$refs.categoryList.assignedAmount = e
    },

    // 业务分类新增、编辑
    addOrEdit(record) {
      if(!this.model.distributionMethod){
        return this.$message.info('请选择分配方式！')
      }

      if(record){
        this.$refs.categoryList.title = '修改'
        this.$refs.categoryList.edit(record)
      }else{
        this.$refs.categoryList.add()
        this.$refs.categoryList.title = '新增'
      }

      this.$refs.categoryList.assignedAmount = this.model.estimatedContractAmount
      this.$refs.categoryList.disableSubmit = false

    },

    // 业务分类删除
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    getProjectNo() {
      // debugger
      if (this.model.isPrepareEstablish == '0') {
        getAction(this.url.getProjectNo, {}).then((res) => {
          if (res.success) {
            let data = res.result.records || res.result
            // debugger;
            this.$set(this.model, 'projectNo', data)
            this.$set(this.modelDefault, 'projectNo', data)
          }
        })
      }
    },
    add() {
      this.generatedFormNumber();
      this.dataSource = []
      this.edit(this.modelDefault);
      this.userName = this.userInfo().empName;// 申请人名称
      this.model.proposer = this.userInfo().empId; // 申请人
      this.model.proposerDeptId = this.userInfo().deptId; // 申请部门
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm');
    },
    edit(record) {
      this.$refs['form'].clearValidate();
      this.$refs.form.resetFields();
      this.isDisableProjectNo = true
      this.model = Object.assign({}, record);
      this.model.lx = 1
      if (this.model.id) {
        this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      }
      getAction('/api/erp/omc/project/erpOmcProjectTask/listById', { id: this.model.id }).then((res) => {
        if (res.length > 0) {
          this.dataSource = res || res.result;
        }
      });
      // 迭代11 临时修改
      // if(record.isPrepareEstablish == '1'){
      // if(record.isPrepareEstablish == '0'){
      //   this.isShowPrepareProject = true
      //   // this.$delete(this.validatorRules,'projectName')
      // } else {
      //   this.isShowPrepareProject = false
      //   this.$set(this.validatorRules,'projectName',[{ required: true, message: '请输入项目名称!' }])
      // }
      this.visible = true;
      this[this.customKey].forEach((val,index) => {
        val.width = this[this.customKey+'width'][index]
      })
    },
    convertMoney() {
      let money = this.model.estimatedContractAmount
      this.$set(this.model, 'estimatedContractcapitalChineseAmount', convertCurrency(money))
      this.getForMoney()
    },
    getForMoney(){
      if(this.dataSource.length>0){

        this.dataSource.forEach(item =>{

          if(parseInt(this.model.estimatedContractAmount)===0){
            item.contractAmount = 0
            item.contractRate = 0
            
          }else{

            if(!this.model.estimatedContractAmount){
              return
            }

            if(this.model.distributionMethod=='1'){
              // 按比例：更改预计合同额，占比不变、对应的分配合同额实时变化
              if(item.contractRate){

                let amount = this.model.estimatedContractAmount * item.contractRate / 100
                item.contractAmount = Math.round((amount + Number.EPSILON) * 100) / 100

                // item.contractAmount = parseFloat(item.contractRate*0.01*parseFloat(this.model.estimatedContractAmount)).toFixed(2)

              }

          }else if(this.model.distributionMethod=='2'){
            // 按金额：更改预计合同额，分配合同额不变、对应的占比实时变化
            if(item.contractAmount){

              let rate = item.contractAmount / this.model.estimatedContractAmount * 100
              item.contractRate = Math.round((rate + Number.EPSILON) * 100) / 100
                // item.contractRate = parseFloat(parseFloat(item.contractAmount) / parseFloat(this.model.estimatedContractAmount)*100).toFixed(2)
              }
            }

          }

        })
      }
    },
    // 投标档案选择
    tenderFinalChange(tenderFinal) {
      // fix:BUG499 立项中的数据由投标档案中带出 start
      this.$set(this.model, 'finalProjectId', tenderFinal.prepareProjectId); // 项目id
      this.$set(this.model, 'prepareProjectId', tenderFinal.prepareProjectId); // 项目id
      this.$set(this.model, 'teamName', tenderFinal.businessTeam); // 经营团队
      this.$set(this.model, 'undertaker', tenderFinal.undertaker); // 项目承接人
      this.$set(this.model, 'year', tenderFinal.year); // 业绩归属年度
      this.$set(this.model, 'ownerUnit', tenderFinal.ownerUnit); // 业主单位
      this.$set(this.model, 'contacts', tenderFinal.ownerLinkman); // 联系人（立项）-》业主联系人（投标申请）
      this.$set(this.model, 'contactTel', tenderFinal.ownerTel); // 联系方式（立项）-》业主联系方式（投标）
      this.$set(this.model, 'areaCode', tenderFinal.projectAddress); // 项目所在地址（立项）-》项目地址（投标申请）
      this.$set(this.model, 'projectAddress', tenderFinal.detailedAddress); // 项目所在地址（立项）-》项目地址（投标申请）
      this.$set(this.model, 'projectName', tenderFinal.projectName); // 项目名称
      // 迭代12 签订单位（对应投标档案中的投标单位）
      this.$set(this.model, 'signUnit', tenderFinal.tenderUnit); // 签订单位
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';

      // 迭代12查看为中标的投标金额
      let param = {
        tenderId: tenderFinal.id,
        bidResult: '1'
      }
      getAction(this.url.queryTenderResultByEntity, param).then((res) => {
        if (res.success) {
          this.$set(this.model, 'estimatedContractAmount', res.result.tenderAmount)
          this.convertMoney()
        }
      })
      this.model.lx = 1;
      // 子表（立项）-》业务分类子表（投标申请）
      getAction(this.url.queryTenderServiceListByTenderId, { id: tenderFinal.id }).then((res) => {
        if (res.success) {
          if (!!res.result && res.result.length > 0) {
            let list = res.result.map((record) => {
              return { categoryCode: record.serviceType, categoryName: record.serviceName, id: record.id }
            })
            this.dataSource = list;
          } else {
            this.dataSource = [];
          }
        }
      })
      // 注释原因: fix:BUG499 立项中的数据由投标档案中带出
      // getAction('/api/erp/omc/project/erpOmcProject/queryById',{ id: tenderFinal.prepareProjectId}).then(res => {
      //   if (res.success) {
      //     if (res.result){
      //       this.$set(this.model, 'finalProjectId', res.result.id)
      //       this.$set(this.model, 'prepareProjectId', res.result.prepareProjectId)
      //       this.$set(this.model, 'projectName', res.result.projectName)
      //       this.$set(this.model, 'projectType', res.result.projectType)
      //       this.$set(this.model, 'teamName', res.result.teamName)
      //       this.$set(this.model, 'undertaker', res.result.undertaker)
      //       this.$set(this.model, 'isBidding', res.result.isBidding)
      //       this.$set(this.model, 'isEnvironmentalAssessmentProject', res.result.isEnvironmentalAssessmentProject)
      //       this.$set(this.model, 'signUnit', res.result.signUnit)
      //       this.$set(this.model, 'year', res.result.year)
      //       this.$set(this.model, 'ownerUnit', res.result.ownerUnit)
      //       this.$set(this.model, 'contacts', res.result.contacts)
      //       this.$set(this.model, 'contactTel', res.result.contactTel)
      //       this.$set(this.model, 'areaCode', res.result.areaCode)
      //       this.$set(this.model, 'projectAddress', res.result.projectAddress)
      //       this.$set(this.model, 'projectSource', res.result.projectSource)
      //       this.$set(this.model, 'estimatedContractAmount', res.result.estimatedContractAmount)
      //       this.$set(this.model, 'estimatedContractcapitalChineseAmount', res.result.estimatedContractcapitalChineseAmount)
      //       this.$set(this.model, 'establishReason', res.result.establishReason)
      //       this.$set(this.model, 'attachment', res.result.attachment)
      //       this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      //       //根据项目id 查看业务分类
      //       getAction('/api/erp/omc/project/erpOmcProjectTask/queryByProjectId', { projectId: this.model.finalProjectId }).then((res) => {
      //         if (res.success) {
      //           this.dataSource = res.result;
      //         }
      //       });
      //       this.model.lx = 1;
      //     }
      //
      //   }
      // })
      // fix:BUG499 立项中的数据由投标档案中带出 end
      // //业绩归属年度
      // this.$set(this.model,'year',tenderFinal.year)
      //
      // //项目名称
      // this.$set(this.model, 'projectName', tenderFinal.projectName)
      // //项目地址
      // this.$set(this.model,'areaCode',tenderFinal.projectAddress)
      // this.$set(this.model,'projectAddress',tenderFinal.detailedAddress)
      // //业主单位
      // this.$set(this.model,'ownerUnit',tenderFinal.ownerUnit)
      // //联系人
      // this.$set(this.model,'contacts',tenderFinal.ownerLinkman)
      // //联系方式
      // this.$set(this.model,'contactTel',tenderFinal.ownerTel)
      // //经营团队
      // this.$set(this.model,'teamName',tenderFinal.businessTeam)
      // //承接人
      // this.$set(this.model,'undertaker',tenderFinal.undertaker)

      // 查询要业务信息档案
      // getAction('/api/erp/omc/tender/erpOmcTenderServiceFinal/queryTenderServiceListByTenderId',{ id: tenderFinal.id }).then(res => {
      //   if(res.success){
      //     this.dataSource = res.result || []
      //   }
      // })
      // getAction('/api/erp/omc/project/erpOmcProject/queryById',{ id: tenderFinal.prepareProjectId}).then(res => {
      //   if(res.success){
      //     //设置预计合同额
      //     this.$set(this.model,'estimatedContractAmount',res.result.estimatedContractAmount)
      //     //设置预计合同额大写
      //     this.$set(this.model, 'estimatedContractcapitalChineseAmount', res.result.estimatedContractcapitalChineseAmount)
      //     //设置项目来源
      //     this.$set(this.model, 'projectSource', res.result.projectSource);
      //     //设置签订单位
      //     this.$set(this.model, 'signUnit', res.result.signUnit);
      //     //设置立项事由
      //     this.$set(this.model, 'establishReason', res.result.establishReason);
      //     //设置立项时间
      //     this.$set(this.model, 'projectEstablishDate',res.result.projectEstablishDate)
      //     // qddw
      //   }
      // })
      // this.$set(this.model,'biddingMethod',tenderFinal.biddingMethod)
      // this.$set(this.model,'tenderContent',tenderFinal.tenderContent)
      // this.$set(this.model,'tenderFile',tenderFinal.tenderFile)
      // this.$set(this.model,'controlPrice',tenderFinal.controlPrice)
      // // BUG#3276
      // this.$set(this.model,'projectPublicity',tenderFinal.projectPublicity)

      // //todo 迭代11 根据投标档案带出数据
      // this.$set(this.model,'tenderUnit',tenderFinal.tenderUnit)

      // // 查询投标单位
      // getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId',{ id: tenderFinal.id }).then(res => {
      //   if (res.success) {
      //     this.dataSource = res.result || []
      //   }
      // })
    },
    contactsChange(val) {
      // debugger
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'contacts', val)
          this.$set(this.model, 'contactTel', data.lxfs)
        }
      })
    },
    ownerUnitChange() {
      this.$set(this.model, 'contacts', null)
      this.$set(this.model, 'contactTel', null)
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
    },

    // 重置表单中基本信息部分数据
    async resetBasicsPortionDataForm() {
      this.$set(this.model, 'finalProjectId', undefined)
      this.$set(this.model, 'projectName', undefined)
      this.$set(this.model, 'teamName', undefined)
      this.$set(this.model, 'undertaker', undefined)
      this.$set(this.model, 'projectEstablishDate', undefined)
      this.$set(this.model, 'signUnit', undefined)
      this.$set(this.model, 'year', undefined)
      this.$set(this.model, 'ownerUnit', undefined)
      this.$set(this.model, 'contacts', undefined)
      this.$set(this.model, 'areaCode', undefined)
      this.$set(this.model, 'projectAddress', undefined)
      this.$set(this.model, 'projectSource', undefined)
      this.$set(this.model, 'estimatedContractAmount', undefined)
      this.$set(this.model, 'contactTel', undefined)
      this.$set(this.model, 'tenderFinalCode', undefined)
      this.$set(this.model, 'estimatedContractcapitalChineseAmount', undefined)
      this.$set(this.model, 'establishReason', undefined) // 立项事由及说明
      this.$set(this.model, 'attachment', null) // 相关附件
      this.dataSource = [] // 子表数据清空
    },

    // 预立项选择
    prepareProjectChange(project) {
      this.$set(this.model, 'finalProjectId', project[0].id)
      this.$set(this.model, 'prepareProjectId', project[0].prepareProjectId)
      this.$set(this.model, 'projectName', project[0].projectName)
      this.$set(this.model, 'bpmBizTitle', project[0].projectName)// 标题
      this.$set(this.model, 'projectType', project[0].projectType)
      this.$set(this.model, 'teamName', project[0].oldTeamId?project[0].oldTeamId:project[0].teamName)
      this.$set(this.model, 'undertaker', project[0].undertaker)
      this.$set(this.model, 'isBidding', project[0].isBidding)
      this.$set(this.model, 'isEnvironmentalAssessmentProject', project[0].isEnvironmentalAssessmentProject)
      this.$set(this.model, 'signUnit', project[0].signUnit)
      this.$set(this.model, 'year', project[0].year)
      this.$set(this.model, 'ownerUnit', project[0].ownerUnit)
      this.$set(this.model, 'contacts', project[0].contacts)
      this.$set(this.model, 'contactTel', project[0].contactTel)
      this.$set(this.model, 'areaCode', project[0].areaCode)
      this.$set(this.model, 'projectAddress', project[0].projectAddress)
      this.$set(this.model, 'projectSource', project[0].projectSource)
      this.$set(this.model, 'estimatedContractAmount', project[0].estimatedContractAmount)
      this.$set(this.model, 'estimatedContractcapitalChineseAmount', project[0].estimatedContractcapitalChineseAmount)
      this.$set(this.model, 'distributionMethod', project[0].distributionMethod)
      this.$set(this.model, 'establishReason', project[0].establishReason)
      this.$set(this.model, 'attachment', project[0].attachment)
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      // 根据项目id 查看业务分类
      this.dataSource = []
      getAction('/api/erp/omc/project/erpOmcProjectTask/queryByProjectId', { projectId: this.model.finalProjectId }).then((res) => {
        if (res.success) {
          this.dataSource = res.result;
        }
      });
      this.model.lx = 1;
    },

    popupCallback(value, row, obj) {
      // this.model = Object.assign(this.model, obj);
      this.$set(this.model, 'bpmBizTitle', obj.project_name)// 标题
      this.$set(this.model, 'undertaker', obj.undertaker)
      this.$set(this.model, 'year', obj.year)
      // this.$set(this.model, 'teamName', obj.teamName)
      this.$set(this.model, 'teamName', obj.business_team)
      this.$set(this.model, 'tenderFinalId', obj.id)
      this.$set(this.model, 'projectName', obj.project_name)
      this.$set(this.model, 'prepareProjectId', obj.prepare_project_id)
      this.$set(this.model, 'projectAddress', obj.project_address)
      this.$set(this.model, 'detailedAddress', obj.detailed_address)
      this.$set(this.model, 'businessTeam', obj.business_team)
      this.$set(this.model, 'entriesEndDate', obj.entries_end_date)
      this.entriesEndDate = obj.entries_end_date
      this.$set(this.model, 'tenderEndDate', obj.tender_end_date)
      this.tenderEndDate = obj.tender_end_date
      this.$set(this.model, 'ownerUnit', obj.owner_unit)
      this.$set(this.model, 'ownerLinkman', obj.owner_linkman)
      this.$set(this.model, 'ownerTel', obj.owner_tel)
      this.$set(this.model, 'biddingMethod', obj.bidding_method)
      this.$set(this.model, 'controlPrice', obj.control_price)
      this.$set(this.model, 'entryFee', obj.entry_fee)
      this.$set(this.model, 'tenderBond', obj.tender_bond)
      this.$set(this.model, 'projectPublicity', obj.project_publicity)
      this.$set(this.model, 'tenderContent', obj.tender_content)
      this.$set(this.model, 'tenderFile', obj.tender_file)
      this.$set(this.model, 'contacts', obj.owner_linkman)
      this.$set(this.model, 'contactTel', obj.owner_tel)
      // this.$set(this.model,'tenderType',obj.tender_type)
      // this.$set(this.model,'baseScore',obj.base_score)
      this.isShowTeamwork = obj.is_teamwork === '1'
      this.$set(this.model, 'isTeamwork', obj.is_teamwork)
      this.$set(this.model, 'teamworkPerson', obj.teamwork_person)
      // 查询要业务信息档案
      getAction('/api/erp/omc/tender/erpOmcTenderServiceFinal/queryTenderServiceListByTenderId', { id: obj.id }).then(res => {
        if (res.success) {
          this.dataSource = res.result || []
        }
      })
      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId', { id: obj.id }).then(res => {
        if (res.success) {
          this.unitDataSource = res.result || []
        }
      })
    },

    // 迭代11 - 2022/10/31
    isPrepareEstablishChange(e) {
      this.resetBasicsPortionDataForm();
      // 迭代11
      // if (e == '1') {
      // if (e == '0') {
      //   this.isShowPrepareProject = true
        // this.$delete(this.validatorRules,'projectName')
        // this.$set(this.model,'prepareProjectId',null)
      // } else {
        // this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0'
        // this.isShowPrepareProject = false
          // this.model.projectName = null;
        // this.$set(this.model,'projectName',null)
        // this.model.projectType = null;
        // this.model.teamName = null;
        // this.model.undertaker = null;
        // this.$set(this.model,'year',null)
        // this.model.isBidding = null;
        // this.model.isEnvironmentalAssessmentProject = null;
        // this.model.signUnit = null;
        // this.model.ownerUnit = null;

        // this.model.contacts = null;
        // this.model.contactTel = null;
        // this.model.areaCode = null;
        // this.model.projectSource = null;

        // this.model.estimatedContractAmount = null;
        // this.model.estimatedContractcapitalChineseAmount = null;
        // this.model.establishReason = null;
        // this.model.attachment = null;
        // this.$set(this.validatorRules,'projectName',[{ required: true, message: '请输入项目名称!' }])
        // this.dataSource = []
      // }

      // if (e == '0') {
      //   this.isShowPrepareProject = true
      //   this.$delete(this.validatorRules,'projectName')
      //   this.$set(this.model,'prepareProjectId',null)
      // }
    },
    generatedFormNumber() {
      getAction(this.url.generatedFormNumber, { prefix: 'LX', subSystemCode: '05' }).then(res => {
        if (res.success) {
          this.$set(this.model, 'projectNo', res.result)
        }
      })
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },

    validateForm() {
      return this.$refs.form.validate().then(async () => {
        if (this.model) {
          var that = this
          if (this.model.isPrepareEstablish === '0') {
            if (!this.model.projectName) {
              that.$message.warning('项目名称不可为空');
              return Promise.reject("项目名称不可为空")
            }
          } else {
            this.dataSource.forEach((item, index) => {
              if (item.id) {
                item.oldId = item.id
              }
            })
          }
        }
        if (!this.dataSource || this.dataSource.length === 0) {
          this.$message.warning('必须填写业务分类信息！');
          return Promise.reject('必须填写业务分类信息！')
        }
        if(this.model.distributionMethod=='1'){

          let rate = 0
          this.dataSource.forEach(val => {
            rate += parseFloat(val.contractRate)
          })
          if(rate!=100&&parseInt(this.model.estimatedContractAmount)!==0){
            this.$message.warning('合同占比相加不等于100%，请重新填写')
            return Promise.reject('合同占比相加不等于100%，请重新填写')
          }

        }else if(this.model.distributionMethod=='2'){
          let total = 0
          this.dataSource.forEach(val => {
            total += parseFloat(val.contractAmount)
          })
          if (total.toFixed(2) != parseFloat(that.model.estimatedContractAmount).toFixed(2)) {
            this.$message.warning('所有分配金额总计和预计合同额不相等，请重新填写')
            return Promise.reject('所有分配金额总计和预计合同额不相等，请重新填写')
          }
        }

        var isJudge = -1
        for (var i = 0; i < this.dataSource.length; i++) {
					var isTrue = await getAction('/api/erp/omc/project/erpOmcProjectApply/valdateProductTeamLeader', { teamId: this.dataSource[i].productTeam }).then((res) => {
						if (res.success) {
							return res.success
						} else {
              isJudge = i
							var info = filterMultiDictText(this.dictOptions['productTeam'], this.dataSource[i].productTeam + '') + '团队，生产负责人岗位未找到'
              this.$message.warning(info);
							return res.success
						}
					})
          if (!isTrue) {
            break
          }
				}
        if (isJudge != -1) {
          return Promise.reject('生产负责人岗位未找到')
        }
      })
    },
    async submitForm() {
      const that = this;
      // 触发表单验证
      await this.validateForm()
      that.confirmLoading = true;
      let httpurl = '';
      let method = '';
      if (!this.model.id) {
        httpurl += this.url.add;
        method = 'post';
      } else {
        httpurl += this.url.edit;
        method = 'put';
      }
      let list = this.dataSource;
      this.model.categoryList = list;
      httpAction(httpurl, this.model, method).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.$emit('ok');
        } else {
          that.$message.warning(res.message);
        }
      }).finally(() => {
        that.confirmLoading = false;
      })
    },

    // 点击打印
    onPrint () {
      this.isPrint = true
      var _this = this
      let print = new Print({
        el: '#projectapplyContent',
        popTitle: '立项申请明细 · 禾美环保',
        endCallback() {
          _this.isPrint = false
        }
      })
    }
  }
}
</script>
<style>
  @import "../../../../../utils/print.css";
  .print_style{
  position: absolute;
  top: 0;
  z-index: -1111;
}
</style>
